package xyz.chaobei.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import xyz.chaobei.entity.OrgPermissionEntity;

import java.util.List;

/**
 * mapper
 * @author mrc
 */
public interface OrgPermissionMapper extends BaseMapper<OrgPermissionEntity> {

    /**
     * @Author MRC
     * @Description 通过角色ID查询出关联的权限信息
     * @Date 11:45 2020/1/21
     * @Param [id]
     * @return java.util.List<xyz.chaobei.entity.OrgPermissionEntity>
     **/
    List<OrgPermissionEntity> findByRoleId(@Param("id") Integer id);

    /**
     * 查询已开通权限，通过父类ID查询
     * @param parent
     * @param permission
     * @return
     */
    List<OrgPermissionEntity> findMenuByParent(@Param("parent") Integer parent,@Param("permission") List<Integer> permission);

    /**
     * @Author MRC
     * @Description 选出多个角色开通的权限ID
     * @Date 16:31 2020/1/23
     * @Param [roles]
     * @return java.util.List<java.lang.Long>
     **/
    List<Integer> findPermissionByRoles(@Param("roles") List<Integer> roles);
    /**
     * 保存角色与权限的关联信息
     * @param permission
     * @param id
     * @return
     */
    int saveRolePermission(@Param("permission") List<Integer> permission, @Param("role") Integer id);
    /**
     *
     * @param id
     * @return
     */
    OrgPermissionEntity findById(Integer id);

    @Update("UPDATE `org_permission` SET `index_` = ${index} where `id_` = #{id}")
    int updateIndex(@Param("index")Integer index, @Param("id")Integer id);
}